/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Class;

import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.FileManager;
import java.io.FileOutputStream;
import java.io.InputStream;

/**
 *
 * @author Edwin, Cristian Dos recursos y cada uno con sus propiedades, ya no se
 * muestra en pantalla si no que se guarda en un archivo
 */
public class Intersection extends Object {

    static String inputFileName1 = "ZonaA.rdf";
    static String inputFileName2 = "ZonaB.rdf";

    public void executeIntersection(String input1, String input2, String fullPath) {
        // TODO code application logic here

        inputFileName1 = input1;
        inputFileName2 = input2;
        Model model1 = ModelFactory.createDefaultModel();
        Model model2 = ModelFactory.createDefaultModel();

        InputStream in = FileManager.get().open(inputFileName1);

        if (in == null) {
            throw new IllegalArgumentException("File 1 :" + inputFileName1 + "Not found");
        }

        InputStream in2 = FileManager.get().open(inputFileName2);

        if (in2 == null) {
            throw new IllegalArgumentException("File 2 :" + inputFileName2 + "Not found");
        }

        model1.read(in, "");
        model2.read(in2, "");

        Model model = model1.intersection(model2);
        model.write(System.out, "RDF/XML-ABBREV");
        System.out.println();

        try {
            FileOutputStream fout = new FileOutputStream(fullPath + "\\result.rdf");
            model.write(fout);
        } catch (Exception e) {
            System.out.println("Exception Caught" + e.getMessage());
        }

    }
}
